package com.ww.demo.servicefactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Spring会自动地将形如(@Service后面的名称，实现该接口的类)注入到该userMap中
 * 在启动后，userMap中就存在两个元素，("student"，StudentServiceImpl)与("teacher"，TeacherServiceImpl)
 */
@Service
public class UserContext {
    @Autowired
    Map<String, UserService> userMap;

    public UserService getUserService(String type) {
        return userMap.get(type);
    }
}
